package dbTable;
import db_properties_path.*;
import java.sql.*;
import java.util.*;
import dbTool.*;


public class RETOPIC extends DBconnection2 {
public RETOPIC(SetPath set){
super(set);
}
public RETOPIC(){
super(new DefaultSetPath());
}
/** Auto Increasment */
/** Primary Key */
/** INTEGER ; java.lang.Integer */private int retopicid;
/** INTEGER ; java.lang.Integer */private int topicid;
/** INTEGER ; java.lang.Integer */private int accountid;
/** VARCHAR ; java.lang.String */private String recontent;
/** DATETIME ; java.sql.Timestamp */private long retopictime;
public int getRetopicid(){
return  retopicid;
}
public void setRetopicid(int retopicid){
this.retopicid= retopicid;
}

public int getTopicid(){
return  topicid;
}
public void setTopicid(int topicid){
this.topicid= topicid;
}

public int getAccountid(){
return  accountid;
}
public void setAccountid(int accountid){
this.accountid= accountid;
}

public String getRecontent(){
return  recontent;
}
public void setRecontent(String recontent){
this.recontent= recontent;
}

public long getRetopictime(){
return  retopictime;
}
public void setRetopictime(long retopictime){
this.retopictime= retopictime;
}

public interface fn{
String TABLE_NAME = "RETOPIC";
String PK = "retopicid";
String retopicid="retopicid";
String topicid="topicid";
String accountid="accountid";
String recontent="recontent";
String retopictime="retopictime";
}
public String sql(String SQL){
return Utility.getSQL組合字(SQL, RETOPIC.fn.class);
}
public int clear() {
String SQL = "delete from RETOPIC";
Object parameter[] = {};
return super.excuteUpdate(SQL, parameter);
}

public int delete(int retopicid) {
String SQL = "delete from RETOPIC where retopicid=?";
Object parameter[] = {retopicid};
return super.excuteUpdate(SQL, parameter);
}

public int update(int topicid,int accountid,String recontent,long retopictime, int retopicid){
String SQL = "update RETOPIC set topicid=?,accountid=?,recontent=?,retopictime=? where retopicid=?";
Object parameter[] = {topicid,accountid,recontent,new Timestamp(retopictime),retopicid};
return super.excuteUpdate(SQL,parameter);
}

public int insert(int topicid,int accountid,String recontent,long retopictime){
String SQL = "insert into RETOPIC(topicid,accountid,recontent,retopictime) values(?,?,?,?)";
Object parameter[] = { topicid,accountid,recontent,new Timestamp(retopictime)};
return super.excuteUpdate(SQL ,parameter);
}

public String[][] select() {
String SQL = "select * from RETOPIC";
Object parameter[] = {};
return super.select(SQL, parameter);
}

public RETOPIC[] select_Object() {
String SQL = "select * from RETOPIC";
Object parameter[] = {};
String data[][] = super.select(SQL, parameter);RETOPIC obj[] = toObject(data);return obj;}

public String[][] select( int retopicid) {
String SQL = "select * from RETOPIC where retopicid=?";
Object parameter[] = {retopicid};
return super.select(SQL, parameter);}

public RETOPIC[] select_Object( int retopicid) {
String data[][] = this.select(retopicid);RETOPIC obj[] = toObject(data);return obj;}

public int selectCount() {
String SQL = "select count(retopicid) from RETOPIC";
Object parameter[] = {};
String d[][] = super.select(SQL, parameter);
return Integer.parseInt(d[0][0]);}

public String[][] selectPage(int pageSize, int pageIndex, int rowCount) {
int desc = PaggingSQL.ASC;PaggingSQL ps = new dbTool.MySQL();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPage(pageSize, pageIndex, TABLE_NAME, PK, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount) {
PaggingSQL ps = new dbTool.MySQL();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
 /**
 * 關鍵字 where 不用寫
 * @param pageSize
 * @param pageIndex
 * @param sortName
 * @param desc
 * @param rowCount
 * @param whereCondition = 【pk>0】, 關鍵字 where 不用寫
 * @return
 */
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount, String whereCondition) {
PaggingSQL ps = new dbTool.MySQL();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;
//範例,關鍵字 where 不用寫, ex:【pk>0】
String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount, whereCondition);Object parameter[] = {};
return super.select(SQL, parameter);
}
public RETOPIC[] selectPage_Object(int pageSize, int pageIndex, int rowCount) {
	String data[][] = this.selectPage(pageSize, pageIndex, rowCount);
	RETOPIC obj[] = toObject(data);
	return obj;
}
 /**
 * 分組統計筆數
 * @param fk_List
 * @return
 */
public Map<Integer, Integer> getGroupCount(String fkName, LinkedList<Integer> fk_List){String q = "";
Object parameter[] = new Object[fk_List.size()];
int i=0;
for (Integer no : fk_List) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();String SQL = "";SQL += "SELECT "+ fkName +", count("+ fkName +") ";SQL += "FROM "+ fn.TABLE_NAME +" where "+fkName+" in (" + q + ")";SQL += "group by "+ fkName +";";String data[][] = super.select(SQL, parameter);for (int j = 0; j < data.length; j++) {int key = Integer.parseInt(data[j][0]);int count = Integer.parseInt(data[j][1]);map.put(key, count);}return map;} /**
 * Where PK in(?,?,?....)
 * @param idList
 * @return
 */
public Map<Integer, RETOPIC> selectMap(LinkedList<Integer> idList){
String q = "";
Object parameter[] = new Object[idList.size()];
int i=0;
for (Integer no : idList) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, RETOPIC> map = new HashMap<Integer, RETOPIC>();

String SQL = "select * from RETOPIC where retopicid in ("+ q +")";
String data[][] = super.select(SQL, parameter);
RETOPIC[] obj = this.toObject(data);
for (RETOPIC o : obj) {
map.put(new Integer(o.retopicid) , o);
}
return map;
}
public RETOPIC[] toObject(String data[][]){
RETOPIC[] obj = new RETOPIC[data.length];
for (int i = 0; i < obj.length; i++) {
obj[i] = new RETOPIC(super.getSetting());obj[i].retopicid=Integer.parseInt(data[i][0]);
obj[i].topicid=Integer.parseInt(data[i][1]);
obj[i].accountid=Integer.parseInt(data[i][2]);
obj[i].recontent=data[i][3];
obj[i].retopictime=Long.parseLong(data[i][4]);
}
return obj;}
}